﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
using WPFExcelReport.Helpers;
using System.Collections.Generic;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class UIABMU : UIABAUFM
    { 
        public UIABMU()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABAUFM();
            this.DataContext = MV;
            MESSAGES += "MUVKAUF;";
            

        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                ABAUF = "";
            }
            else
            {
                ABAUF = dwMaster["ABAAUFTYP"].ToString() + dwMaster["ABAAUFKRS"].ToString() + dwMaster["ABAAUFLFD"].ToString() + dwMaster["ABAAUFPOS"].ToString() + dwMU["ABPPOSTYP"].ToString();
                PM["AUFTYP"] = dwMaster["ABAAUFTYP"].ToString();
                PM["ORDERNUM"] = ABAUF.Substring(1);
                PM["RUNID"] = RUNID;
                TMV.VABP.LOADABP(PM);//仅仅发送消息
            }
        }

        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                LOADBYAUF();
            }
            else
            {
                VICC_WFEVENTS.SVWF.GP02(this.RUNID);
            }
            base.ManageCommand(sender, e);
        }
        public override void OnEXAUFChg(string value)
        {

            TMV.VKAUF = EXAUF;
            TBMain.Clear();
            EXTPROD = "";
            if (EXAUF.Length < 11)
                return;
            PM["VKAUF"] = EXAUF;
            TMV.LOADBYVKAUF(PM);
            foreach (DataRow row in TBMain.Rows)
            {
                if (row["ABAAUFKRS"].ToString() == "FB")
                    continue;
                EXTPROD = row["ABAAUFKRS"].ToString() + row["ABAAUFLFD"].ToString() + row["ABAAUFPOS"].ToString();
            }
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM.Length < 11)
                return;
            PM["ORDERNUM"] = ORDERNUM;
            PM["AUFTYP"] = ORDERNUM.Substring(0, 1);
            PM["KRS"] = ORDERNUM.Substring(1, 2);
            PM["LFD"] = ORDERNUM.Substring(3, 6);
            PM["POS"] = ORDERNUM.Substring(9, 3);
            TMV.LOAD(PM);
            vwMaster.View.MoveCurrentToFirst();
        }

    }
     
}
